﻿using Script.Audio;
using Script.Character;
using Script.Net;
using Script.Scene;
using Script.UI;
using UnityEngine;

namespace Script.Framework
{
    /// <summary>
    /// 消息处理中心
    ///     自负责消息的转发
    /// </summary>
    public class MsgCenter : MonoBehaviour
    {
        public static MsgCenter instance;

        private void Awake()
        {
            instance = this;

            gameObject.AddComponent<AudioManager>();
            gameObject.AddComponent<UIManager>();
            gameObject.AddComponent<NetManager>();
            gameObject.AddComponent<SceneMgr>();
            gameObject.AddComponent<CharacterManager>();


            DontDestroyOnLoad(transform.gameObject);
        }

        public void Dispatch(int areaCode, int eventCode, object message)
        {
            switch (areaCode)
            {
                case AreaCode.AUDIO:
                    AudioManager.instance.Execute(eventCode, message);
                    break;
                case AreaCode.CHARACTER:
                    CharacterManager.sInstance.Execute(eventCode, message);
                    break;
                case AreaCode.NET:
                    NetManager.instance.Execute(eventCode, message);
                    break;
                case AreaCode.GAME:
                    break;
                case AreaCode.UI:
                    UIManager.mInstance.Execute(eventCode, message);
                    break;
                case AreaCode.SCENE:
                    SceneMgr.instance.Execute(eventCode, message);
                    break;
            }
        }
    }
}